/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

Ext.QuickTips.init();
var _pageSize = 20;
var _pageSizeSmall = 10;

var fieldName = ['id', 'name', 'x', 'y', 'h', 'pointTypeId', 'pointType', 'pointType2Id', 'pointType2', 'voltageLevelId', 'voltageLevelName', 'status', 'note', 'updateTime',
    'creatTime', 'orgCode', 'deptId', 'fromId', 'lowerLimit', 'upperLimit', 'pointArea', 'pointPosition', 'userName', 'publicName', 'deviceId', 'code', 'company', 'installSite',
    'manufactoryName', 'model', 'commTypeName', 'mobileNo', 'ip', 'terminalNo', 'installTime', 'checkTime', 'effectTime', 'stopTime', 'stopReason', 'expireTime', 'produceTime', 'port',
    'uniqueCode', 'zbm', 'adminAreaCode', 'channel', 'runTime', 'subCompany', 'shortName', 'stationVoltageLevel', 'realName', 'deviceType', 'lastHBTime', 'lastUploadTime', 'lastTalk', "isOffline", 'startStatusCh', 'reportStatusCh', "startStatus"];
var fieldLabel = ['ID', '监测点名称', '经度', '纬度', '高度', '监测点类型ID（类别1）', '监测点类型(类别1)', '电网类型ID（类别2）', '电网类别（类别2）', '电压等级ID', '电压等级', '状态',
    '备注', '记录的更新时间', '记录的创建时间', '机构编码', '所属部门编码', '上级监测点', '电压下限', '电压上限', '用户名称', '公变名称', '设备ID', '监测点编码', '供电局', '安装位置',
    '生产厂家', '装置型号', '通信方式', '通信卡号', 'IP地址', '终端编号', '安装日期', '校验日期', '生效日期', '停用日期', '停用原因', '有效期', '出厂日期', '端口', '唯一码', '组编码', '行政区域码',
    '通道', '投运日期', '部门分县局', '供电所', '所属变电站电压等级', '管理人员', '装置类别', '在线离线', '上报观测', '启用停用', '上次心跳时间', '上次上传数据时间', '最后通信时间'];

var saveServlet = basePath + 'servlet/system/PointSave';
var loadServlet = basePath + 'servlet/system/PointLoad';


var StopDetailServlet = basePath + 'servlet/point/StopDetailUpdate';

var theme = '监测点运行';

var _title = currentOrgName + theme + '管理';

var now = new Date();

function getIds(rs) {
    var jsonData = "";
    var jsonDataDevices = "";
    for (var i = 0, len = rs.length; i < len; i++) {
        var ss = rs[i].get("id"); //这里为Grid数据源的Id列
        var ssDevices = rs[i].get("deviceId");
        if (i === 0) {
            jsonData = jsonData + ss;
            jsonDataDevices = jsonDataDevices + ssDevices;
        } else {
            jsonData = jsonData + "," + ss;
            jsonDataDevices = jsonDataDevices + "," + ssDevices;
        }
    }
    return {pointIds: jsonData, deviceIds: jsonDataDevices};
}

function getPointNames(rs, n) {
    var jsonData = "";
    for (var i = 0, len = rs.length; i < len; i++) {
        var ss = rs[i].get(n);
        if (i === 0) {
            jsonData = jsonData + ss;
        } else {
            jsonData = jsonData + "," + ss;
        }
    }
    return jsonData;
}


var storeUser = new Ext.data.JsonStore({
    url: '../../../servlet/system/UserLoad',
    root: 'data',
    idProperty: 'id',
    totalProperty: 'count',
    fields: ['id', 'employeeNo', 'loginName', 'realName', 'shortName', 'email']
});
var checkboxSelUser = new Ext.grid.CheckboxSelectionModel({singleSelect: true});
var userGrid = new Ext.grid.GridPanel({
    store: storeUser,
    sm: checkboxSelUser,
    //autoHeight: true,
    height: 350,
    //disableSelection:true,
    columns: [
        checkboxSelUser,
        {header: 'ID', sortable: true, dataIndex: 'id', hidden: true},
        {header: '工号', width: 100, sortable: true, dataIndex: 'employeeNo'},
        {header: '姓名', width: 100, sortable: true, dataIndex: 'realName'},
        {header: '登录名', width: 100, sortable: true, dataIndex: 'loginName'},
        {header: '单位', width: 150, sortable: true, dataIndex: 'shortName'}
    ],
    loadMask: true,
    bbar: new Ext.PagingToolbar({
        pageSize: _pageSizeSmall,
        store: storeUser,
        displayInfo: true,
        displayMsg: '显示记录：{0} - {1}   总记录：{2}',
        emptyMsg: "目前没有用户信息"
    })
});

var userWin = new Ext.Window({
    title: '选择用户',
    id: 'UserWin',
    width: 600,
    height: 350,
    modal: true,
    autoHeight: true,
    resizable: true,
    layout: 'fit',
    closable: true,
    closeAction: 'hide',
    items: [userGrid],
    buttons: [{
            text: '保存',
            iconCls: 'icon-save',
            handler: function () {
                if (checkboxSelUser.getSelections().length === 0) {
                    Ext.Msg.alert("系统提示", "您还没有选择用户");
                    return;
                }
                var recordUser = checkboxSelUser.getSelected();
                var recordPoints = checkboxSel.getSelections();
                var pointIds = getIds(recordPoints);
                var token1 = new Date().getTime();
                var conn = new Ext.data.Connection();
                conn.request({
                    url: saveServlet,
                    params: {token: token, token1: token1, userId: recordUser.get('id'), pointIds: pointIds.pointIds, cmd: 'allocate'},
                    method: 'post',
                    scope: this,
                    callback: function (options, success, response) {
                        checkboxSelUser.clearSelections();
                        userWin.hide();
                        if (success) {
                            var messager = Ext.decode(response.responseText);
                            store.reload();
                            if (messager.success) {
                                Ext.MessageBox.alert("提示", "保存成功");
                            } else {
                                Ext.Msg.alert('提示', messager.msg);
                            }

                        } else {
                            Ext.MessageBox.alert("提示", "保存失败！");
                        }
                    }
                });
            }
        }, {
            text: '取消',
            handler: function () {
                checkboxSelUser.clearSelections();
                userWin.hide();
            }
        }]
});

function allocate() {
    if (checkboxSel.getSelections().length === 0) {
        Ext.Msg.alert("系统提示", "您还没有选择，需要先选择才能配置装置");
    } else {
        storeUser.load({params: {start: 0, limit: _pageSizeSmall}});
        userWin.show();
    }
}

var startForm = new Ext.FormPanel(
        {
            xtype: 'form',
            id: 'StartForm',
            bodyStyle: 'padding:15px;background:transparent',
            frame: true,
            border: false,
            url: saveServlet,
            items: [{
                    name: 'pointNames',
                    xtype: 'textarea',
                    id: 'PointNamesStart',
                    width: 180,
                    height: 250,
                    readOnly: true,
                    diable: true,
                    fieldLabel: '所选监测点',
                    allowBlank: false,
                    blankText: '监测点名称必须填写'
                }
                , {
                    name: 'effectTime',
                    id: 'EffectTime',
                    width: 180,
                    xtype: 'datefield',
                    fieldLabel: '测点生效日期',
                    format: 'Y-m-d',
                    allowBlank: false
                }
            ],
            buttons: [{
                    text: '启用',
                    iconCls: 'icon-control_play',
                    handler: function () {
                        var submitConfig = {
                            success: function (form, action) {
                                winStart.hide();
                                store.reload();
                            },
                            failure: function (form, action) {
                                switch (action.failureType) {
                                    case Ext.form.Action.CONNECT_FAILURE:
                                        Ext.Msg.alert('提示', '网络连接失败');
                                        break;
                                    case Ext.form.Action.SERVER_INVALID:
                                        Ext.Msg.alert('提示', action.result.msg);
                                }
                            },
                            params: {}
                        };
                        var ids = getIds(checkboxSel.getSelections());
                        //alert(ids.pointIds);
                        submitConfig.params.pointIds = ids.pointIds;
                        submitConfig.params.deviceIds = ids.deviceIds;
                        submitConfig.params.cmd = 'start';
                        var token1 = new Date().getTime();
                        submitConfig.params.token = token;
                        submitConfig.params.token1 = token1;
                        Ext.getCmp('StartForm').getForm().submit(submitConfig);
                    }
                }, {
                    text: '取消',
                    handler: function () {
                        winStart.hide();
                    }
                }]
        }
);
var winStart = new Ext.Window({
    layout: 'form',
    width: 400,
    autoHeight: true,
    closeAction: 'hide',
    items: [startForm]
});

function startpoint() {
    if (checkboxSel.getSelections().length === 0) {
        Ext.Msg.alert("系统提示", "您还没有选择，需要先选择才能配置装置");
    } else {
        var pointNames = getPointNames(checkboxSel.getSelections(), 'name');
        Ext.getCmp('PointNamesStart').setValue(pointNames);
        Ext.getCmp('EffectTime').setValue(now);
        winStart.show();
    }
}
var stopForm = new Ext.FormPanel(
        {
            xtype: 'form',
            id: 'StopForm',
            bodyStyle: 'padding:15px;background:transparent',
            frame: true,
            border: false,
            url: saveServlet,
            items: [{
                    name: 'pointNames',
                    xtype: 'textarea',
                    id: 'PointNamesStop',
                    width: 180,
                    height: 200,
                    readOnly: true,
                    diable: true,
                    fieldLabel: '所选监测点',
                    allowBlank: false,
                    blankText: '监测点名称必须填写'
                }
                , {
                    name: 'stopTime',
                    id: 'StopTime',
                    width: 180,
                    xtype: 'datefield',
                    fieldLabel: '测点停用日期',
                    format: 'Y-m-d',
                    allowBlank: false
                }, {
                    name: 'stopReason',
                    id: 'StopReason',
                    width: 180,
                    height: 100,
                    allowBlank: false,
                    blankText: '停用原因有必须填写',
                    fieldLabel: '停用原因',
                    xtype: 'textarea'
                }
            ],
            buttons: [{
                    text: '停用',
                    iconCls: 'icon-control_stop',
                    handler: function () {
                        var submitConfig = {
                            success: function (form, action) {
                                winStop.hide();
                                store.reload();
                            },
                            failure: function (form, action) {
                                switch (action.failureType) {
                                    case Ext.form.Action.CONNECT_FAILURE:
                                        Ext.Msg.alert('提示', '网络连接失败');
                                        break;
                                    case Ext.form.Action.SERVER_INVALID:
                                        Ext.Msg.alert('提示', action.result.msg);
                                }
                            },
                            params: {}
                        };
                        var ids = getIds(checkboxSel.getSelections());
                        //alert(ids.pointIds);
                        submitConfig.params.pointIds = ids.pointIds;
                        submitConfig.params.deviceIds = ids.deviceIds;
                        submitConfig.params.cmd = 'stop';
                        var token1 = new Date().getTime();
                        submitConfig.params.token = token;
                        submitConfig.params.token1 = token1;
                        Ext.getCmp('StopForm').getForm().submit(submitConfig);
                    }
                }, {
                    text: '取消',
                    handler: function () {
                        winStop.hide();
                    }
                }]
        }
);
var winStop = new Ext.Window({
    layout: 'form',
    width: 400,
    autoHeight: true,
    closeAction: 'hide',
    items: [stopForm]
});

function stoppoint() {
    rs = checkboxSel.getSelections();
    if (checkboxSel.getSelections().length === 0) {
        Ext.Msg.alert("系统提示", "您还没有选择监测点");
    } else {
        var jsonData = "";
        for (var i = 0, len = rs.length; i < len; i++) {
            var ss = rs[i].get("name");
            var startStatus = rs[i].get("startStatus");
            if (startStatus == 0) {
                Ext.Msg.alert("系统消息", "选择中不能包括已停用的监测点");
                return;
            }
            if (i === 0) {
                jsonData = jsonData + ss;
            } else {
                jsonData = jsonData + "," + ss;
            }
        }
        //var pointNames = getPointNames(checkboxSel.getSelections(), 'name');
        Ext.getCmp('PointNamesStop').setValue(jsonData);
        Ext.getCmp('StopTime').setValue(now);
        winStop.show();
    }
}

var storeFromPoint = new Ext.data.JsonStore({
    url: '../../../servlet/system/PointLoad',
    root: 'data',
    idProperty: 'id',
    totalProperty: 'count',
    fields: ['id', 'name', 'shortName', 'company', 'pointTypeId', 'pointType', 'pointType2Id', 'pointType2', 'voltageLevelId', 'voltageLevelName']
    , baseParams: {start: 0, limit: _pageSize, cmd: "run"}
    , autoLoad: true
});
var checkboxSelFromPoint = new Ext.grid.CheckboxSelectionModel({singleSelect: true});
var frompointGrid = new Ext.grid.GridPanel({
    store: storeFromPoint,
    sm: checkboxSelFromPoint,
    //autoHeight: true,
    height: 350,
    //disableSelection:true,
    columns: [
        checkboxSelFromPoint,
        {header: 'ID', sortable: true, dataIndex: 'id', hidden: true},
        {header: '监测点名称', width: 100, sortable: true, dataIndex: 'name'},
        {header: '部门分县局', width: 100, sortable: true, dataIndex: 'shortName'},
        {header: '供电局', width: 100, sortable: true, dataIndex: 'company'},
        {header: '监测点类型', width: 80, sortable: true, dataIndex: 'pointType'},
        {header: '电网类型', width: 60, sortable: true, dataIndex: 'pointType2'},
        {header: '电压等级', width: 100, sortable: true, dataIndex: 'voltageLevelName', align: 'right'}
    ],
    loadMask: true,
    tbar: tbarFromPoint,
    bbar: new Ext.PagingToolbar({
        pageSize: _pageSize,
        store: storeFromPoint,
        displayInfo: true,
        displayMsg: '显示记录：{0} - {1}   总记录：{2}',
        emptyMsg: "目前没有" + theme + '信息'
    }),
    listeners: {
        'render': function () {
            tbarFromPoint.render(this.tbar);
        }
    }
});

var frompointWin = new Ext.Window({
    title: '选择上级监测点',
    id: 'FrompointWin',
    width: 600,
    height: 350,
    modal: true,
    autoHeight: true,
    resizable: true,
    layout: 'fit',
    closable: true,
    closeAction: 'hide',
    items: [frompointGrid],
    buttons: [{
            text: '保存',
            iconCls: 'icon-save',
            handler: function () {
                if (checkboxSelFromPoint.getSelections().length === 0) {
                    Ext.Msg.alert("系统提示", "您还没有选择用户");
                    return;
                }
                var recordFromPoint = checkboxSelFromPoint.getSelected();
                var recordPoints = checkboxSel.getSelections();
                var pointIds = getIds(recordPoints);
                var token1 = new Date().getTime();
                var conn = new Ext.data.Connection();
                conn.request({
                    url: saveServlet,
                    params: {token: token, token1: token1, frompointId: recordFromPoint.get('id'), pointIds: pointIds.pointIds, cmd: 'frompoint'},
                    method: 'post',
                    scope: this,
                    callback: function (options, success, response) {
                        checkboxSelFromPoint.clearSelections();
                        frompointWin.hide();
                        if (success) {
                            var messager = Ext.decode(response.responseText);
                            store.reload();
                            if (messager.success) {
                                Ext.MessageBox.alert("提示", "保存成功");
                            } else {
                                Ext.Msg.alert('提示', messager.msg);
                            }

                        } else {
                            Ext.MessageBox.alert("提示", "保存失败！");
                        }
                    }
                });
            }
        }, {
            text: '取消',
            handler: function () {
                checkboxSelFromPoint.clearSelections();
                frompointWin.hide();
            }
        }]
});

function frompoint() {
    if (checkboxSel.getSelections().length === 0) {
        Ext.Msg.alert("系统提示", "您还没有选择，需要先选择才能配置上级监测点");
    } else {
        storeFromPoint.load({params: {start: 0, limit: _pageSizeSmall}});
        frompointWin.show();
    }
}



var type = 1;         //判断打开窗口是进行更新，还是新建。1-新建；2-修改
var updated = false;

var inputFormStopDetail = new Ext.FormPanel({
    xtype: 'form',
    id: 'InputFormStopDetail',
    bodyStyle: 'padding:15px;background:transparent',
    frame: true,
    border: false,
    url: StopDetailServlet,
    items: [{
            name: "id",
            xtype: 'textfield',
            fieldLabel: "ID",
            hidden: true
        }
        , {
            name: 'pointName',
            id: "StopDetailPointName",
            xtype: 'textfield',
            fieldLabel: '监测点名称',
            width: 180,
            readOnly: true
        }
        , {
            name: 'pointId',
            xtype: 'textfield',
            id: "StopDetailPointId",
            fieldLabel: 'PointID',
            hidden: true
        }, {
            name: 'effectTime',
            id: 'StopDetailEffectTime',
            width: 180,
            xtype: 'datefield',
            fieldLabel: '测点生效日期',
            format: 'Y-m-d',
            allowBlank: false
        }, {
            name: 'stopTime',
            id: 'StopDetailStopTime',
            width: 180,
            xtype: 'datefield',
            fieldLabel: '停用日期',
            format: 'Y-m-d',
            allowBlank: false
        }, {
            name: 'stopReason',
            id: "StopDetailStopReason",
            xtype: 'textarea',
            fieldLabel: '停止原因',
            width: 180,
            height: 50,
            allowBlank: false,
            maxLength: 100,
            maxLengthText: '字数不能大于100'
        }
    ],
    buttons: [{
            text: '保存',
            iconCls: 'icon-save',
            handler: function () {
                var submitConfig = {
                    success: function (form, action) {
                        storeStopDetail.reload();
                        winStopDetailEdit.hide();
                    },
                    failure: function (form, action) {
                        switch (action.failureType) {
                            case Ext.form.Action.CONNECT_FAILURE:
                                Ext.Msg.alert('提示', '网络连接失败');
                                break;
                            case Ext.form.Action.SERVER_INVALID:
                                Ext.Msg.alert('提示', action.result.msg);
                        }
                    },
                    params: {}
                };
                var token1 = new Date().getTime();
                submitConfig.params.token = token;
                submitConfig.params.token1 = token1;
                if (type === 1)
                    submitConfig.params.cmd = 'create';
                else {
                    submitConfig.params.cmd = 'update';
                    submitConfig.params.id = checkboxSelStopDetail.getSelected().get("id");
                }
                Ext.getCmp('InputFormStopDetail').getForm().submit(submitConfig);
            }
        }, {
            text: '取消',
            handler: function () {
                winStopDetailEdit.hide();
            }
        }]
});
var winStopDetailEdit = new Ext.Window({
    layout: 'form',
    width: 340,
    autoHeight: true,
    closeAction: 'hide',
    modal: true,
    items: [inputFormStopDetail]
});

function addStopDetail() {
    type = 1;
    winStopDetailEdit.setTitle('增加起停明细');
    //Ext.getCmp('InputFormStopDetail').getForm().reset();
    Ext.getCmp('StopDetailEffectTime').reset();
    Ext.getCmp('StopDetailStopTime').reset();
    Ext.getCmp('StopDetailStopReason').reset();
    winStopDetailEdit.show();
}

function updateStopDetail() {
    if (checkboxSelStopDetail.getSelections().length === 0) {
        Ext.Msg.alert("系统提示", "您还没有选择，需要选择一个记录才能修改");
    } else if (checkboxSelStopDetail.getSelections().length > 1) {
        Ext.Msg.alert("系统提示", "您选择了多个记录，只能选择一个记录进行修改");
    } else {
        type = 2;
        Ext.getCmp('InputFormStopDetail').getForm().loadRecord(checkboxSel.getSelected());
        var temp = checkboxSelStopDetail.getSelected().get('effectTime');
        r = Date.parseDate(temp, 'yy-m-d H:i:s.u', false);
        Ext.getCmp('StopDetailEffectTime').setValue(r);

        temp = checkboxSelStopDetail.getSelected().get('stopTime');
        r = Date.parseDate(temp, 'yy-m-d H:i:s.u', false);
        Ext.getCmp('StopDetailStopTime').setValue(r);

        winStopDetailEdit.setTitle('修改起停明细');
        winStopDetailEdit.show();
    }
}

function delStopDetail() {
    if (checkboxSelStopDetail.getSelections().length === 0) {
        Ext.Msg.alert("系统提示", "您还没有选择，需要先选择才能删除");
    } else if (checkboxSelStopDetail.getSelections().length > 1) {
        Ext.Msg.alert("系统提示", "您选择了多个记录，一次只能删除一条记录");
    } else {
        var msg;
        msg = "确实要删除所选的记录吗?";
        Ext.MessageBox.confirm('系统提示', msg, function (btn) {
            if (btn === 'yes') {
                var records = checkboxSelStopDetail.getSelections();
                var jsonData = "";
                for (var i = 0, len = records.length; i < len; i++) {
                    var ss = records[i].get("id"); //这里为Grid数据源的Id列
                    if (i === 0)
                        jsonData = jsonData + ss;
                    else
                        jsonData = jsonData + "," + ss;
                }
                var token1 = new Date().getTime();
                var conn = new Ext.data.Connection();
                conn.request({
                    url: StopDetailServlet, //提交的删除地址
                    params: {token: token, token1: token1, cmd: "remove", ids: jsonData},
                    method: 'post',
                    scope: this,
                    callback: function (options, success, response) {
                        if (success) {
                            var messager = Ext.decode(response.responseText);
                            if (messager.success) {
                                Ext.MessageBox.alert("系统提示", "所选记录成功删除！");
                                storeStopDetail.reload(); //重新load数据                                
                            } else {
                                Ext.Msg.alert('系统提示', messager.msg);
                            }
                        } else {
                            Ext.MessageBox.alert("系统提示", "所选记录删除失败！");
                        }
                    }
                });
            }
        });
    }

}

var storeStopDetail = new Ext.data.JsonStore({
    url: '../../../servlet/point/StopDetailLoad',
    root: 'data',
    idProperty: 'id',
    totalProperty: 'count',
    fields: ['id', 'pointId', 'name', 'effectTime', 'stopTime', 'stopReason']
});

var checkboxSelStopDetail = new Ext.grid.CheckboxSelectionModel({singleSelect: true});
var stopDetailGrid = new Ext.grid.GridPanel({
    store: storeStopDetail,
    sm: checkboxSelStopDetail,
    //autoHeight: true,
    height: 350,
    //disableSelection:true,
    columns: [
        checkboxSelStopDetail,
        {header: 'ID', sortable: true, dataIndex: 'id', hidden: true},
        {header: '监测点名称', width: 150, sortable: true, dataIndex: 'name'},
        {header: '启用时间', width: 120, sortable: true, dataIndex: 'effectTime', xtype: 'datecolumn', format: 'Y-m-d'},
        {header: '停用时间', width: 120, sortable: true, dataIndex: 'stopTime', xtype: 'datecolumn', format: 'Y-m-d'},
        {header: '停用原因', width: 150, sortable: true, dataIndex: 'stopReason'}
    ],
    loadMask: true,
    tbar: new Ext.Toolbar([
        {text: '新增', iconCls: 'icon-add', handler: addStopDetail},
        {text: '修改', iconCls: 'icon-edit', handler: updateStopDetail},
        {text: '删除', iconCls: 'icon-delete', handler: delStopDetail}
    ]),
    bbar: new Ext.PagingToolbar({
        pageSize: _pageSizeSmall,
        store: storeStopDetail,
        displayInfo: true,
        displayMsg: '显示记录：{0} - {1}   总记录：{2}',
        emptyMsg: "目前没有明细信息"
    })
});

var stopDetailWin = new Ext.Window({
    title: '监测点起停历史',
    id: 'StopDetailWin',
    width: 600,
    height: 350,
    modal: true,
    autoHeight: true,
    resizable: true,
    layout: 'fit',
    closable: true,
    closeAction: 'hide',
    items: [stopDetailGrid],
    buttons: [{
            text: '取消',
            handler: function () {
                stopDetailWin.hide();
            }
        }]
});

function stopDetailManage() {
    if (checkboxSel.getSelections().length === 0) {
        Ext.Msg.alert("系统提示", "您还没有选择监测点");
    } else if (checkboxSel.getSelections().length > 1) {
        Ext.Msg.alert("系统提示", "您选择了多项，一次只能选择一项");
    } else {
        var r = checkboxSel.getSelected();
        var pointId = r.get("id");
        var pointName = r.get("name");
        //alert(Ext.getCmp("StopDetailPointName").setValue);

        //alert(pointName);
        Ext.getCmp("StopDetailPointId").setValue(pointId);
        Ext.getCmp("StopDetailPointName").setValue(pointName);
        //alert(Ext.getCmp("StopDetailPointName").value);
        storeStopDetail.baseParams.pointId = pointId;
        storeStopDetail.load({params: {start: 0, limit: _pageSizeSmall}});
        stopDetailWin.show();
    }
}



var checkboxSel = new Ext.grid.CheckboxSelectionModel();
var store;
function buildWindow() {
    store = new Ext.data.JsonStore({
        url: loadServlet,
        root: 'data',
        idProperty: 'id',
        totalProperty: 'count',
        fields: fieldName
        , baseParams: {start: 0, limit: _pageSize, cmd: "run"}
        , autoLoad: true
    });

    var grid = new Ext.grid.GridPanel({
        title: _title,
        store: store,
        sm: checkboxSel,
        autoExpandColumn: fieldLabel[12],
        columns: [
            checkboxSel,
            {header: fieldLabel[0], sortable: true, dataIndex: fieldName[0], hidden: true},
            {header: "状态", dataIndex: 'startStatus', width: 40,
                renderer: function (v, metaData, record, rowIndex, colIndex, store) {
                    var value = parseInt(v);
                    var imageName;
                    if (value > 0) {
                        imageName = 'record_green.png';
                        return "<image src='" + basePath + "image/icon/" + imageName + "'/>";
                    } else
                        imageName = 'record_red.png';
                    return "<image src='" + basePath + "image/icon/" + imageName + "'/>";
                }
            },
            {header: '供电局', width: 100, sortable: true, dataIndex: 'company'},
            {header: '部门分县局', width: 100, sortable: true, dataIndex: 'subCompany'},
            {header: '监测点编码', width: 100, sortable: true, dataIndex: 'code'},
            {header: '监测点名称', width: 100, sortable: true, dataIndex: 'name'},
            {header: '监测点类型', width: 100, sortable: true, dataIndex: 'pointType'},
            {header: '电网类型', width: 100, sortable: true, dataIndex: 'pointType2'},
            {header: '启用停用', width: 80, sortable: true, dataIndex: 'startStatusCh'},
            {header: '上报观测', width: 80, sortable: true, dataIndex: 'reportStatusCh'},
            {header: '在线离线', width: 80, sortable: true, dataIndex: 'isOffline'},
            {header: '上次心跳时间', width: 80, sortable: true, dataIndex: 'lastHBTime', xtype: 'datecolumn', format: 'Y-m-d'},
            {header: '上次上传数据时间', width: 80, sortable: true, dataIndex: 'lastUploadTime', xtype: 'datecolumn', format: 'Y-m-d'},
            {header: '最后通信时间', width: 80, sortable: true, dataIndex: 'lastTalk', xtype: 'datecolumn', format: 'Y-m-d'},
            {header: '电压等级', width: 100, sortable: true, dataIndex: 'voltageLevelName', align: 'right'},
            {header: '电压上限', width: 100, sortable: true, dataIndex: 'upperLimit', xtype: 'numbercolumn', format: '0.00', align: 'right'},
            {header: '电压下限', width: 100, sortable: true, dataIndex: 'lowerLimit', xtype: 'numbercolumn', format: '0.00', align: 'right'},
            {header: '测点地域', width: 100, sortable: true, dataIndex: 'pointArea'},
            {header: '测点位置', width: 100, sortable: true, dataIndex: 'pointPosition'},
            {header: '供电所', width: 100, sortable: true, dataIndex: 'shortName'},
            {header: '所属变电站电压等级', width: 120, sortable: true, dataIndex: 'stationVoltageLevel'},
            {header: '用户名称', width: 120, sortable: true, dataIndex: 'userName'},
            {header: '公变名称', width: 120, sortable: true, dataIndex: 'publicName'},
            {header: '安装位置', width: 120, sortable: true, dataIndex: 'installSite'},
            {header: '生产厂家', width: 120, sortable: true, dataIndex: 'manufactoryName'},
            {header: '装置类别', width: 80, sortable: true, dataIndex: 'deviceType'},
            {header: '装置型号', width: 80, sortable: true, dataIndex: 'model'},
            {header: '通信方式', width: 80, sortable: true, dataIndex: 'commTypeName'},
            {header: '通信卡号', width: 120, sortable: true, dataIndex: 'mobileNo'},
            {header: 'IP地址', width: 120, sortable: true, dataIndex: 'ip'},
            {header: '终端编号', width: 80, sortable: true, dataIndex: 'terminalNo'},
            {header: '安装日期', width: 80, sortable: true, dataIndex: 'installTime', xtype: 'datecolumn', format: 'Y-m-d'},
            {header: '校验日期', width: 80, sortable: true, dataIndex: 'checkTime', xtype: 'datecolumn', format: 'Y-m-d'},
            {header: '生效日期', width: 80, sortable: true, dataIndex: 'effectTime', xtype: 'datecolumn', format: 'Y-m-d'},
            //{header: '投运日期', width: 120, sortable: true, dataIndex: 'runTime', xtype: 'datecolumn', format: 'Y-m-d'},
            {header: '停用日期', width: 80, sortable: true, dataIndex: 'stopTime', xtype: 'datecolumn', format: 'Y-m-d'},
            {header: '停用原因', width: 80, sortable: true, dataIndex: 'stopReason'},
            {header: '有效期', width: 80, sortable: true, dataIndex: 'expireTime', xtype: 'datecolumn', format: 'Y-m-d'},
            {header: '出厂日期', width: 80, sortable: true, dataIndex: 'produceTime', xtype: 'datecolumn', format: 'Y-m-d'},
            {header: '端口', width: 80, sortable: true, dataIndex: 'port'},
            {header: '唯一码', width: 120, sortable: true, dataIndex: 'uniqueCode'},
            {header: '组编码', width: 80, sortable: true, dataIndex: 'zbm'},
            {header: '行政区域码', width: 80, sortable: true, dataIndex: 'adminAreaCode'},
            {header: '通道', width: 80, sortable: true, dataIndex: 'channel'},
            {header: '管理人员', width: 80, sortable: true, dataIndex: 'realName'},
            {header: '备注', id: '备注', width: 80, sortable: true, dataIndex: 'note'}
        ],
        loadMask: true,
        tbar: new Ext.Toolbar([
            {text: '分配装置', iconCls: 'icon-appUser', handler: allocate},
            {text: '关联上级监测点', iconCls: 'icon-appUser', handler: frompoint},
            {text: '启用', iconCls: 'icon-control_play', handler: startpoint},
            {text: '停用', iconCls: 'icon-control_stop', handler: stoppoint}, "-",
            {text: '启停历史维护', iconCls: 'icon-history', handler: stopDetailManage}

        ]),
        bbar: new Ext.PagingToolbar({
            pageSize: _pageSize,
            store: store,
            displayInfo: true,
            displayMsg: '显示记录：{0} - {1}   总记录：{2}',
            emptyMsg: "目前没有" + theme + '信息'
        }),
        listeners: {
            'render': function () {
                tbarPoint.render(this.tbar);
            }
        }
    });
    var applicationUI = new Ext.Viewport({
        layout: "fit",
        items: [
            grid
        ]
    });
}
Ext.onReady(buildWindow);
